function surface = surface1D(varargin)
% REQUIREMENTS:
% - x and h should be in the same unit
%
% FIELDS:
% - x
% - h
% - dx
%
% EXAMPLES:
%  surface = surface1D(x,h);
%  surface = surface1D(filename,x_max,format);

switch nargin
    case 2
        if isvector(varargin{1}) && isvector(varargin{2}) && length(varargin{1})==length(varargin{2}) 
            % Syntax: surface = surface1D(x,h)
            x = varargin{1};
            surface.x = x;
            surface.dx = x(2)-x(1);
            surface.h = varargin{2};
        end
    case 3
        % Syntax: surface = surface1D(filename,x_max)
        snapshot_file=varargin{1};
        x_max = varargin{2};
        flag_format = varargin{3};
        switch flag_format
            case 'KMC'
                data = load(snapshot_file);
                h = data(:,1);
            case 'PDE'
                h = load(snapshot_file);
            otherwise
                error('Error');
        end
        if size(h,2)==1
            h = h';
        end
        number_of_points = length(h);
        dx = x_max/number_of_points;
        surface.x = linspace(0,x_max-dx,number_of_points);
        surface.dx = dx;
        surface.h = h;
    otherwise
        fprintf(1,'Unfinished\n');
end
surface = class(surface,'surface1D');
    